# U-Boot: ODROID-X/X2/U2/U3
# Maintainer: Kevin Mihelich <kevin@archlinuxarm.org>

buildarch=4

pkgbase=uboot-odroid
pkgname=('uboot-odroid' 'uboot-odroid-x')
pkgver=2015.07
pkgrel=1
arch=('armv7h')
url='http://www.denx.de/wiki/U-Boot/WebHome'
license=('GPL')
install=$pkgname.install
backup=('boot/uEnv.txt')
makedepends=('bc' 'dtc' 'git')
_commit=dd9a970aa4accf5d266d334c0f319c674e933027
source=("ftp://ftp.denx.de/pub/u-boot/u-boot-${pkgver}.tar.bz2"
        "https://github.com/hardkernel/u-boot/raw/${_commit}/sd_fuse/bl1.HardKernel"
        "https://github.com/hardkernel/u-boot/raw/${_commit}/sd_fuse/bl2.HardKernel"
        "https://github.com/hardkernel/u-boot/raw/${_commit}/sd_fuse/tzsw.HardKernel"
        "sd_fusing.sh"
        '0001-arch-linux-arm-modifications.patch'
        '0002-odroid-x-support.patch'
        'uEnv.txt')
md5sums=('3dac9a0b46fed77fc768ad3bd2d68c05'
         '3ab6d3cc2061bc2590d60320254017c6'
         '841502de02bd42f2898e36c89c260b0f'
         'c38faafa02a6a1ae834457f378c82113'
         '17909ae93a0ae7b4c155234040105035'
         '5f6296fe2c79b2b799fb4420bafbca60'
         'ff6e82e3c0bf31aff53572e759e30bca'
         'fb5c9ea3108afa298087549f0453b00f')

prepare() {
  cd u-boot-${pkgver}

  git apply ../0001-arch-linux-arm-modifications.patch
}

build() {
  cd u-boot-${pkgver}

  unset CFLAGS
  unset CXXFLAGS
  unset CPPFLAGS

  # build for X2/U2/U3
  make distclean 
  make odroid_config
  make EXTRAVERSION=-${pkgrel}
  mv u-boot-dtb.bin ../u-boot-dtb.bin

  # patch and build for X
  git apply ../0002-odroid-x-support.patch
  make distclean
  make odroid_config
  make EXTRAVERSION=-${pkgrel}
}

package_uboot-odroid() {
  pkgdesc="U-Boot for ODROID-X2/U2/U3"

  cd u-boot-${pkgver}
  mkdir -p ${pkgdir}/boot
  cp ../u-boot-dtb.bin ${pkgdir}/boot/u-boot.bin
  cp ../uEnv.txt ${pkgdir}/boot
  cp ../{{bl1,bl2,tzsw}.HardKernel,sd_fusing.sh} ${pkgdir}/boot
}

package_uboot-odroid-x() {
  pkgdesc="U-Boot for ODROID-X"

  cd u-boot-${pkgver}
  mkdir -p ${pkgdir}/boot
  cp u-boot-dtb.bin ${pkgdir}/boot/u-boot.bin
  cp ../uEnv.txt ${pkgdir}/boot
  cp ../{{bl1,bl2,tzsw}.HardKernel,sd_fusing.sh} ${pkgdir}/boot
}
